<?php
declare (strict_types=1);
namespace Upload;
use Config;
use RuntimeException;

class Repository implements UploadInterface
{
    private mixed $instance;

    protected array $config = [];
    public function __construct()
    {
        $config =  Config::get("upload");
        $driverClass = ucfirst($config['driver']);
        $class = ("Upload\Driver\\") . $driverClass;
        $this->instance = new $class($config);
        if (! $this->instance) {
            throw new RuntimeException($driverClass." is class not exist ");
        }
    }

     public function upload(array|string $files = []): bool|array
     {
         return $this->instance->upload($files);
     }

     public function getError(): string
     {
         return $this->instance->getError();
     }
}
